package com.example.ssoapp1.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * IndexController
 *
 * @author majun
 * @description IndexController
 * @date 2021/9/7
 */
@Controller
@RequestMapping
public class IndexController {

    @Value("${app.domain}")
    private String domain;

    @Value("${server.port}")
    private String port;

    @GetMapping("home")
    public String home(HttpSession session, Model model, HttpServletRequest request) {

        Object user = session.getAttribute("user");
        model.addAttribute("domain", domain);
        model.addAttribute("port", port);
        if (user == null) {
            model.addAttribute("isLogin", false);
        } else {
            model.addAttribute("isLogin", true);
            model.addAttribute("user", user.toString());
        }
        return "home";
    }
}
